'use strict';
/**
 * Created by FreezeSoul on 2015/9/30.
 */
define([
        'angular',
        'adConfig',
        'app/modules/dataset/define'
    ],
    function (angular, adConfig) {
        angular.module('ad.dataset')
            .controller('adDateSetParamController', ['$scope', '$uibModalInstance', '_', 'items', function ($scope, $uibModalInstance, _, items) {

                $scope.items =  angular.copy(items);

                $scope.sqlParamTypes = adConfig.sqlParamTypes;

                $scope.ok = function () {
                    $uibModalInstance.close($scope.items);
                };

                $scope.cancel = function () {
                    $uibModalInstance.dismiss('cancel');
                };

                $scope.add = function(){
                    $scope.items.push({
                        ParamName: '新增',
                        DataType: '',
                        DefaultValue: ''
                    });
                };

                $scope.remove = function(item){
                    var index = $scope.items.indexOf(item);
                    if (index > -1) {
                        $scope.items.splice(index, 1);
                    }
                };

                $scope.checkInvalid = function (items) {
                    return _.every(items, function (item) {
                        return item.ParamName != "" && item.DataType != "";
                    }) != true;
                }
            }]);
    });